package com.example.blog.model;

import com.example.blog.enums.ResultStatus;
import lombok.Data;

@Data
public class  Result <T>{
    private ResultStatus code;
    private String msg;
    private T data;

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode(ResultStatus.SUCCESS);
        result.setMsg("");
        result.setData(data);
        return result;
    }


    public static <T> Result <T> fail(String errmsg) {
        Result<T> result = new Result<>();
        result.setCode(ResultStatus.FAIL);
        result.setMsg(errmsg);
        result.setData(null);
        return result;
    }


    public static <T> Result <T> fail(String errmsg,T data) {
        Result<T> result = new Result<>();
        result.setCode(ResultStatus.FAIL);
        result.setMsg(errmsg);
        result.setData(data);
        return result;
    }


    public static <T> Result <T> nologin() {
        Result<T> result = new Result<>();
        result.setCode(ResultStatus.NOLOGIN);
        result.setMsg("用户未登录");
        result.setData(null);
        return result;
    }
}
